package com.ikkong.platform.controller;

import java.util.Map;
import com.ikkong.core.base.BaseController;
import com.ikkong.core.dao.Blade;
import com.ikkong.core.jfinal.ext.kit.JsonKit;
import com.ikkong.core.toolbox.Record;
import com.ikkong.system.controller.base.UrlPermissController;
import com.ikkong.platform.model.Info;
import com.ikkong.platform.service.InfoService;
import com.ikkong.platform.service.impl.InfoServiceImpl;
import com.sun.deploy.cache.BaseLocalApplicationProperties;

/**
 * Generated by Blade.
 * 2018-09-14 21:12:29
 */
public class InfoController extends UrlPermissController {
	private static String CODE = "info";
	private static String PERFIX = "info";
	private static String LIST_SOURCE = "Info.list";
	private static String BASE_PATH = "/platform/info/";
	
	InfoService service = new InfoServiceImpl();
	
	public void index() {
		setAttr("code", CODE);
		render(BASE_PATH + "info.html");
	}

	public void add() {
		setAttr("code", CODE);
		render(BASE_PATH + "info_add.html");
	}

	public void edit() {
		String id = getPara(0);
        Map map = Blade.dao().selectSingle("Info.one", Record.create().set("id", id), Map.class);
		setAttr("model", JsonKit.toJson(map));
		setAttr("id", id);
		setAttr("code", CODE);
		render(BASE_PATH + "info_edit.html");
	}

	public void view() {
		String id = getPara(0);
		Info info = service.findById(id);
		setAttr("model", JsonKit.toJson(info));
		setAttr("id", id);
		setAttr("code", CODE);
		render(BASE_PATH + "info_view.html");
	}

	public void list() {
		Object grid = paginate(LIST_SOURCE);
		renderJson(grid);
	}

	public void save() {
		Info info = mapping(PERFIX, Info.class);
		boolean temp = service.save(info);
		if (temp) {
			renderJson(success(SAVE_SUCCESS_MSG));
		} else {
			renderJson(error(SAVE_FAIL_MSG));
		}
	}

	public void update() {
		Info info = mapping(PERFIX, Info.class);
		boolean temp = service.update(info);
		if (temp) {
			renderJson(success(UPDATE_SUCCESS_MSG));
		} else {
			renderJson(error(UPDATE_FAIL_MSG));
		}
	}

	public void remove() {
		String ids = getPara("ids");
		int cnt = service.deleteByIds(ids);
		if (cnt > 0) {
			renderJson(success(DEL_SUCCESS_MSG));
		} else {
			renderJson(error(DEL_FAIL_MSG));
		}
	}
}
